/**
 * Created with IntelliJ IDEA
 * Description:
 * User: Administrator
 * Data: 2023 - 07 - 26
 * Time: 12:38
 */
//牛客：JZ36二叉搜索树与双向链表
class TreeNode {
    int val = 0;
    TreeNode left = null;
    TreeNode right = null;

    public TreeNode(int val) {
        this.val = val;
    }
}
public class Solution1 {
    TreeNode head = null;
    TreeNode curPre = null;
    public TreeNode Convert(TreeNode pRootOfTree) {
        if(pRootOfTree == null) return null;
        Convert(pRootOfTree.left);
        if(curPre == null) {//因为当前节点为空时在上面一定会返回null，所以代码来到这一行时，当前节点一定不为空
            curPre = pRootOfTree;
            head = pRootOfTree;
        }else {
            curPre.right = pRootOfTree;
            pRootOfTree.left = curPre;
            curPre = pRootOfTree;
        }
        Convert(pRootOfTree.right);
        return head;
    }
}
